import pandas as pd
cancel = ["visible", "visible.1", "manually-marked-outlier", "sensor-type", "individual-taxon-canonical-name",
          "study-name", "NCEP NARR SFC Vegetation at Surface"]
f = open("C:\\TEST\\python\\数据分析 migration_original.csv")
df = pd.read_csv(f)
f.close()
for i in cancel:
    del df[i]

df.to_csv("C:\\TEST\\python\\version1.csv", index=False)
df = pd.read_csv("C:\\TEST\\python\\version1.csv")

grouped = df.groupby("tag-local-identifier")
a = []
for name, group in grouped:
    a.append(name)
for i in a:
    grouped.get_group(i).to_csv("C:\\TEST\\python\\grouped\\{}.csv".format(i), index=False)


df = pd.read_csv("C:\\TEST\\python\\version1.csv")
grouped = df.groupby("tag-local-identifier")
a = []
for name, group in grouped:
    a.append(name)
f = open('C:\\TEST\\python\\ID_list2.txt','w')
for i in a:
    x=grouped.get_group(i).shape[0]
    if x>=100:
        grouped.get_group(i).to_csv("C:\\TEST\\python\\grouped1\\{}.csv".format(i), index=False)
        f.write(str(i)+'\n')
f.close()


df = pd.read_csv("C:\\TEST\\python\\version1.csv")
grouped = df.groupby("tag-local-identifier")
a = []
for name, group in grouped:
    a.append(name)
f=open('C:\\TEST\\python\\ID_list1.txt', 'w')
for i in a:
    f.write(str(i)+'\n')
f.close()
